package com.yuncool.sky.system.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.yuncool.sky.system.domain.User;
import com.yuncool.sky.system.mapper.UserMapper;
import com.yuncool.sky.system.pojo.form.UserForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther XIE
 * @Date 2019/11/22 22:17
 * @Description 用户服务类
 * @Version 1.0
 */
@Service
public class UserService extends ServiceImpl<UserMapper, User> {
    @Autowired
    UserMapper userMapper;

    /**
     * 判断用户是否存在
     *
     * @param user
     * @return
     */
    public String selectUser(User user) {
        Integer integer = userMapper.selectCount(new QueryWrapper<User>()
                .lambda()
                .eq(User::getUserNumber, user.getUserNumber())
                .eq(User::getUserPassword, user.getUserPassword()));
        if (integer > 0) {
            return "00";
        }
        return "01";
    }

    /**
     * 用户列表
     *
     * @param userForm
     * @return
     */
    public List<User> sysUserList(UserForm userForm) {
        PageHelper.startPage(userForm.getPages(), userForm.getPageSize());
        return this.list();
    }
}
